package com.xyh.student.controller;

import com.xyh.student.entity.Course;
import com.xyh.student.service.CourseService;
import com.xyh.student.entity.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping("course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    // 1--查询全部课程
    @GetMapping("/getCourses")
    @ResponseBody
    public ResponseData findAllCourses(){
        return this.courseService.getCourses();
    }

    // 2--更新课程
    @PostMapping("/update")
    @ResponseBody
    public ResponseData update(@RequestBody Course course){
        System.out.println(course.toString());
//        course.getTime().toString()
        return this.courseService.updateCourse(course);
    }

    // 3-- 新增一条课程记录
    @PostMapping("/insert")
    @ResponseBody
    public ResponseData insert(@RequestBody Course course){
        return this.courseService.insertCourse(course);
    }

    // 4-- 删除一条记录
    @PostMapping("/deleteByName")
    @ResponseBody
    public ResponseData deleteByName(String name){
        return this.courseService.deleteByName(name);
    }

    // 5-- 多选框批量删除
    @PostMapping("/deletesByNames")
    @ResponseBody
    public ResponseData deletesByNames(String[] names){
        return this.courseService.deletesByNames(names);
    }

    // 6-- 获取课程总数
    @GetMapping("/numberOfCourse")
    @ResponseBody
    public ResponseData numberOfCourse(){
        return this.courseService.numberOfCourse();
    }

    // 7-- 根据名称查找课程
    @GetMapping("/queryByName")
    @ResponseBody
    public ResponseData queryByName(String name){
        return this.courseService.queryByName(name);
    }

    // 8-- 分页显示课程
    @GetMapping("/findByPage")
    @ResponseBody
    public ResponseData findByPage(Integer page, Integer size){
        return this.courseService.findByPage(page,size);
    }

    // 9-- 根据id删除课程
    @GetMapping("/deleteById")
    @ResponseBody
    public ResponseData deleteById(Integer id){
        return this.courseService.deleteById(id);
    }

    // 10-- 根据id批量删除课程
    @PostMapping("/deletesById")
    @ResponseBody
    public ResponseData deletesById(@RequestBody int[] ids){
        System.out.println(ids);
        return this.courseService.deletesById(ids);
    }
}
